<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/component/commonTagLib.jsp" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title><spring:message code="message.listForm.yaoPinKuGuanLi"/></title>
    <%@ include file="/WEB-INF/component/commonCSS.jsp" %> 
    <!--[if lt IE 9]>
        <script src="lib/js/html5shiv.min.js"></script>
        <script src="lib/js/respond.min.js"></script>
    <![endif]-->
    

</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">

    <section class="content-header">
        <h1><spring:message code="message.lable.proddruginfoSTDsee"/></h1>
        <ol class="breadcrumb">
            <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i><spring:message code="message.lable.first"/></a></li>
            <li class="active"><a href="#"><spring:message code="message.lable.StdManage"/></a></li>
            <li class="active"><a href="#"><spring:message code="message.lable.proddruginfoStd"/></a></li>
            <li class="active"><a href="#"><spring:message code="message.lable.proddruginfoSeeStd"/></a></li>
        </ol>
    </section>
    
    
    <section class="content">
        
        <div class=" box box-success">
            <div class="box-body">
              <form action="${ctx}/stdProdDrugInfo/exportExcel.html" id="exportExcel" method="post">
              <input id="fileName" name="fileName" type="hidden" value="<spring:message code="message.lable.prodDrugInfoxls"/>" />
                <div class="input">
                	<div class="textalign1"><spring:message code="message.listForm.tongYongMing"/><spring:message code="message.yanZheng.maoHao"/></div>
                    <div class="boxinput">
                        <input type="text" class="textinput" id="qualityspecName" name="qualityspecName" placeholder="<spring:message code="message.listForm.tongYongMing"/>"/>
                    </div>
                    <div class="textalign"><spring:message code="message.listForm.yaoPinBianMa"/><spring:message code="message.yanZheng.maoHao"/></div>
                    <div class="boxinput">
                        <input type="text" class="textinput" id="drugcode" name="drugCode" placeholder="<spring:message code="message.listForm.yaoPinBianMa"/>"/>
                    </div>
                    <div class="textalign"><spring:message code="message.listForm.shengChanQiYe"/><spring:message code="message.yanZheng.maoHao"/></div>
                    <div class="boxinput">
                         <input type="text" class="textinput" id="prodCompName" name="prodCompName" placeholder="<spring:message code="message.listForm.shengChanQiYe"/>"/>
                    </div>
                </div>
               
                <div class="input">
                    <div class="textalign1"><spring:message code="message.lable.status"/><spring:message code="message.yanZheng.maoHao"/></div>
                    <div class="boxinput">
                        <select class="textinput"  id="status" name="status">
                            <option value=""><spring:message code="message.select.option"/></option>
                            <option value="1"><spring:message code="message.button.start"/></option>
                            <option value="2"><spring:message code="message.button.stop"/></option>
                            <option value="3"><spring:message code="message.button.combine"/></option>
                        </select>
                    </div>
                    <div class="textalign" >
                         <button id="selectDrug" type="button" onclick="gridSerch(1);" class="btn btn-success btn-sm"><spring:message code="message.button.seachSpacing"/></button>
                    </div>
                </div>
            </form>
            </div>
          </div>
        
        <table class="jqgrid" id="gridlist"></table>
        <div id="gridpage"></div>
        <div class=" box box-warning bottongroup">
            <ms:btn url="/stdProdDrugInfo/add.html"><a href="${ctx}/stdProdDrugInfo/add.html?opType=0" class="btn btn-default btn-sm" ><spring:message code="message.button.addSpacing"/></a></ms:btn>
            <ms:btn url="/stdProdDrugInfo/changeEnabled.html"><label  onclick="changeEnabled(1)" class="btn btn-default btn-sm"><spring:message code="message.button.startSpacing"/></label></ms:btn>
            <ms:btn url="/stdProdDrugInfo/changeDisabled.html"><label onclick="changeDisabled(2)" class="btn btn-default btn-sm"><spring:message code="message.button.stopSpacing"/></label></ms:btn>
            <ms:btn url="/stdProdDrugInfo/toMergeProdDrugInfo.html"><label onclick="mergeDrugInfo();" class="btn btn-default btn-sm"><spring:message code="message.button.combineSpacing"/></label></ms:btn>
            <label onclick="exportExcel();" class="btn btn-default btn-sm"><spring:message code="message.lable.daoChu"/></label>
        </div>

    </section>
    <%@ include file="/WEB-INF/component/commonJS.jsp" %> 
    <script type="text/javascript">
    
    //绑定回车
    $('#drugcode,#qualityspecName,#prodCompName,#status').bind('keydown', function(event) {
        if (event.keyCode == "13") {        //13 位电脑上回车键的位置代码
            $('#selectDrug').click();
        }
    }); 
  
    $("#qualityspecName").focus();//加载页面光标在第一个查询框内
    
	    function mergeDrugInfo() {
	        $.HN.window.open({
	            "id" : "mergeDrugInfo",
	            "title" : "<spring:message code="message.lable.proddruginfoSTDmerge"/>",
	            "url" : "${ctx}/stdProdDrugInfo/toMergeProdDrugInfo.html",
	            "callback" : function(args) {
	                
	            }
	        });
	    }
	    
    
        
        $(function () {
            
            $("#gridlist").jqGrid({
                url: "${ctx}/stdProdDrugInfo/getStdProdDrugInfoList.html",
                mtype: "POST",
                datatype: "json",
                autowidth: true,
                shrinkToFit:false,
                height: 270,
                colNames: [
                           '<spring:message code="message.jqGrid.cz"/>',
                           'prodId',
                           '<spring:message code="message.listForm.yaoPinBianMa"/>', 
                           '<spring:message code="message.listForm.tongYongMing"/>', 
                           '<spring:message code="message.listForm.jiXing"/>', 
                           '<spring:message code="message.listForm.guiGe"/>', 
                           '<spring:message code="message.listForm.zhuanHuanXiShu"/>',
                           '<spring:message code="message.listForm.danWei"/>',
                           '<spring:message code="message.listForm.caiZhi"/>',
                           '<spring:message code="message.listForm.shengChanQiYe"/>',
                           '<spring:message code="message.lable.status"/>'
                           ],
                colModel: [
					{ name: 'operate', width: 130, align: "center",sortable: false, 
					    formatter : function(val, opts, rowdata) {
						    var str = "";
						    str += "<ms:btn url='/stdProdDrugInfo/edit.html'><a href='${ctx}/stdProdDrugInfo/edit.html?opType=1&prodId="+rowdata.prodId+"' style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat 0px 0px' class='opIcon' title='<spring:message code="message.jqGrid.cz.bianJi"/>'></a></ms:btn>";
						    str +="<ms:btn url='/stdProdDrugInfo/toStdProdDrugInfoDetail.html'><a href='${ctx}/stdProdDrugInfo/toStdProdDrugInfoDetail.html?prodId="+rowdata.prodId+"' style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat -100px 0px' class='opIcon' title='<spring:message code="message.jqGrid.cz.xiangQing"/>'></a></ms:btn>";
						    str +="<ms:btn url='/stdProdDrugInfo/toMergeProdDrugInfoLog.html'><a href='${ctx}/stdProdDrugInfo/toMergeProdDrugInfoLog.html?prodId="+rowdata.prodId+"' style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat 0px -20px' class='opIcon' title='<spring:message code="message.jqGrid.cz.mergeSee"/>'></a></ms:btn>";
							str +="<ms:btn url='/stdProdDrugInfo/toStdProdDrugInfoLogList.html'><a href='${ctx}/stdProdDrugInfo/toStdProdDrugInfoLogList.html?prodId="+rowdata.prodId+"&code="+rowdata.drugCode+"&name="+rowdata.qualityspecName+"' style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat -120px 0px' class='opIcon' title='<spring:message code="message.jqGrid.cz.weiHuJiLu"/>'></a></ms:btn>";
						    return str;
					    }
					},
                    { name: 'prodId', width: 120 ,hidden:true, align:"center",sortable: false},
                    { name: 'drugCode', width: 120 , align:"center",sortable: false},
                    { name: 'qualityspecName', width: 160 , align:"left" ,sortable: false},
                    { name: 'formName', width: 80 , align:"center" ,sortable: false},
                    { name: 'specName', width: 80 , align:"left" ,sortable: false},
                    { name: 'factor', width: 80 , align:"center" ,sortable: false},
                    { name: 'unitName', width: 80 , align:"center" ,sortable: false},
                    { name: 'materialName', width: 80 , align:"center" ,sortable: false},
                    { name: 'compName', width: 180 , align:"left",sortable: false,
                        formatter:function(cellvalue, options, row){
                            return '<a href="javascript:showCompInfo(\''+ row.compId +'\');">'+(cellvalue || '')+'</a>';
                        }
                    },
                    { name: 'status', width: 60 , align:"center",sortable: false,
                    	cellattr:function (rowId, val, rawObject, cm) {
                	    	if(val == '停用'){
                	    		return 'style="color:red"';
                	    	}
                        },
                        formatter:function(cellvalue, options, row){
                            if (cellvalue == 1) {
                                return "<spring:message code="message.listForm.QiYong"/>";
                            } else if (cellvalue == 3) {
                                return "<spring:message code="message.button.combine"/>";
                            }
                            return "<spring:message code="message.listForm.TingYong"/>";
                        }
                    }
                ],
                rowNum: 20,
                rowList: [10,20,50,100],
                rownumbers: true,
                pager: "#gridpage",
                multiselect: true, 
                viewrecords: true,
                caption: "<spring:message code="message.list.proddruginfoStdlist"/>",
                jsonReader: {
                    repeatitems: false,
                    id: "prodId"
                },
                gridComplete:function(){
                    //序号列宽度自适应（参数为jqgridID）
                    autoRNWidth("gridlist");
                    //数据只有一条时默认选中（参数为jqgridID）
                    selectByOneData("gridlist");
                },
            });
            $("#gridlist").jqGrid('navGrid', '#gridpage', { add: false, edit: false, del: false, search: false, refresh: false });
            $(window).trigger("resize");  
            
        });
        

        //查询
        function gridSerch(page) {
            var drugcode = $("#drugcode").val();
            var qualityspecName = $("#qualityspecName").val();
            var prodCompName = $("#prodCompName").val();
            var status = $("#status").val();
            $("#gridlist").jqGrid('setGridParam',{  
                datatype:'json',
                "page" : (page || 1),
                postData:{
                	"drugCode":drugcode,
                    "qualityspecName":qualityspecName,
                    "prodCompName":prodCompName,
                    "status":status}
            }).trigger("reloadGrid"); //重新载入  
        }
        
        
        //启用（包括批量启用）
        function changeEnabled(status) {
        	var msg="";
        	if (status == 1){
        		msg = "<spring:message code="message.button.start"/>";
        	} else if (status == 2){
        		msg = "<spring:message code="message.button.stop"/>";
        	}
            var rowIds = $("#gridlist").jqGrid("getGridParam", "selarrrow") || [];
            if (rowIds.length <= 0) {
                $.alert("<spring:message code="message.lable.pleaseSelect"/><spring:message code="message.listForm.QiYong"/><spring:message code="message.lable.de"/><spring:message code="message.list.yaoPin"/><spring:message code="message.yanZheng.ganTanHao"/>", "warn");
                return;
            }
            
            var data = "";
			var list = [];
			for(var i = 0;i<rowIds.length;i++){
				var sta =  $("#gridlist").jqGrid('getRowData',rowIds[i]);
				if(sta.status == "<spring:message code="message.listForm.TingYong"/>"){
					var qualityspecName = sta.qualityspecName;
					
					data += qualityspecName+",";
					list.push({"prodId":rowIds[i]});
				}else{
					
				}  
			}
			if(data){
				data = data.substring(0,data.length-1);
			}else{
				$.alert("<spring:message code="message.lable.pleaseSelect"/><spring:message code="message.listForm.QiYong"/><spring:message code="message.lable.de"/><spring:message code="message.list.yaoPin"/><spring:message code="message.yanZheng.ganTanHao"/>", "warn");
				return;
			}
			//获取选中的ID及对应的名字（参数:jqgridId,名字列名，状态列名，当前操作即列表中显示的值），返回infos[0]是ID串，infos[1]是名字串
        	var infos = batchSwitchStatus("gridlist","qualityspecName","status",msg,"<spring:message code='message.listForm.tongYongMing'/>");
        	if ( !(infos instanceof Array)){
        		return;
        	} 
        	$.HN.message.confirm("<spring:message code="message.list.queDingTingYongYiXiaYaoPinMa"/><spring:message code="message.yanZheng.wenHao"/><br/>"+infos[1].replace(/\,/g,"<br/>"), '', '').on(function (e) {
             /* $.HN.message.confirm("<spring:message code="message.list.queDingQiYongYiXiaYaoPinMa"/><spring:message code="message.yanZheng.wenHao"/><br/>"+data, '', '').on(function (e) { */
                if (e) {
                    $.post("${ctx}/stdProdDrugInfo/changeEnabled.html", {
                        "array" : json.jsonToString(list)
                    }, function(result) {
                        if (result.success) {
                            var curpage = $("#gridlist").jqGrid('getGridParam', 'page');
                            gridSerch(curpage);
                            $.alert("<spring:message code="message.HN.alert.chengGong"/>"+msg+''+result.conditions.sum+"<spring:message code="message.lable.tiao"/><spring:message code="message.list.yaoPin"/><spring:message code="message.yanZheng.ganTanHao"/>", "success");
                        } else {
                            $.alert(result.msg ||"<spring:message code="message.HN.alert.fail"/>", "error");
                        }
                    }, "json");
                }
            }); 
            
        }
            
            
            
        
        
        //停用（包括批量停用）
        function changeDisabled(status) {
        	var msg = "";
        	if (status == 1){
        		msg = "<spring:message code="message.button.start"/>";
        	} else if (status == 2){
        		msg = "<spring:message code="message.button.stop"/>";
        	}
            var rowIds = $("#gridlist").jqGrid("getGridParam", "selarrrow") || [];
            if (rowIds.length <= 0) {
                $.alert("<spring:message code="message.lable.pleaseSelect"/><spring:message code="message.listForm.TingYong"/><spring:message code="message.lable.de"/><spring:message code="message.list.yaoPin"/><spring:message code="message.yanZheng.ganTanHao"/>", "warn");
                return;
            }    
            
            var data = "";
			var list = [];
			for(var i = 0;i<rowIds.length;i++){
				var sta =  $("#gridlist").jqGrid('getRowData',rowIds[i]);
				if(sta.status == "<spring:message code="message.listForm.QiYong"/>"){
					var qualityspecName = sta.qualityspecName;
					
					data += qualityspecName+",";
					list.push({"prodId":rowIds[i]});
				}else{
				
				}  
			}
			if(data){
				data = data.substring(0,data.length-1);
			}else{
				$.alert("<spring:message code="message.lable.pleaseSelect"/><spring:message code="message.listForm.TingYong"/><spring:message code="message.lable.de"/><spring:message code="message.list.yaoPin"/><spring:message code="message.yanZheng.ganTanHao"/>", "warn");
				return;
			}
			//获取选中的ID及对应的名字（参数:jqgridId,名字列名，状态列名，当前操作即列表中显示的值），返回infos[0]是ID串，infos[1]是名字串
        	var infos = batchSwitchStatus("gridlist","qualityspecName","status",msg,"<spring:message code='message.listForm.tongYongMing'/>");
        	if ( !(infos instanceof Array)){
        		return;
        	} 
            $.HN.message.confirm("<spring:message code="message.list.queDingTingYongYiXiaYaoPinMa"/><spring:message code="message.yanZheng.wenHao"/><br/>"+infos[1].replace(/\,/g,"<br/>"), '', '').on(function (e) { 
            	/* $.HN.message.confirm('<spring:message code='message.button.confirm' />'+msg+'<spring:message code='message.HN.alert.yiXiaZhangHao' /><spring:message code='message.yanZheng.wenHao' /><br/>'+infos[1].replace(/\,/g,"<br/>"), '', '').on(function (e) { */
                if (e) {
                    $.post("${ctx}/stdProdDrugInfo/changeDisabled.html", {
                        "array" : json.jsonToString(list)
                    }, function(result) {
                        if (result.success) {
                            var curpage = $("#gridlist").jqGrid('getGridParam', 'page');
                            gridSerch(curpage);
                            $.alert("<spring:message code="message.HN.alert.chengGong"/>"+msg+''+result.conditions.sum+"<spring:message code="message.lable.tiao"/><spring:message code="message.list.yaoPin"/><spring:message code="message.yanZheng.ganTanHao"/>", "success");
                        } else {"+infos[0].split(",").length+"
                            $.alert(result.msg ||"<spring:message code="message.HN.alert.fail"/>", "error");
                        }
                    }, "json");
                }
            }); 
            
        }
        
        
        //生产企业弹窗
        function showCompInfo(compId) {
            $.HN.dialog.open({
                "id": "showCompInfo", 
                "title": "<spring:message code="message.listForm.ShengChanQiYeXinXi"/>", 
                "url": "${ctx}/stdCompinfo/toStdCompinfoDetail.html?compId="+compId,
                "data": {}, 
                "width": 800, 
                "height": 400, 
                "closefunc":function() {
                    
                }
            });
        }
        
        function exportExcel(){
 	           $("#exportExcel").submit();
        }
        
    </script>
</body>
</html>